#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAXN=5e4+10;
int n,d,a[MAXN],ans[MAXN];
LL _sum;
bool judge(LL x)
{
	LL cnt=0;
	int j=1;
	for(int i=1;i<=d;++i)
	{
		cnt>>=1;
		while(j<=n&&cnt<x)
			cnt+=a[j++];
		if(cnt<x)return false;
	}
	return true;
}
void cal(LL x)
{
	LL cnt=0;
	int j=1;
	for(int i=1;i<=d;++i)
	{
		cnt>>=1;
		while(j<=n&&cnt<x)
		{
			ans[j]=i;
			cnt+=a[j++];
		}
	}
	for(int i=j+1;i<=n;++i)ans[i]=d;
	return;
}
int main()
{
	scanf("%d%d",&n,&d);
	for(int i=1;i<=n;++i)
	{
		scanf("%d",&a[i]);
		_sum+=a[i];
	}
	LL l=0,r=_sum;
	while(l<=r)
	{
		LL mid=(l+r)>>1;
		if(judge(mid))l=mid+1;
		else r=mid-1;
	}
	printf("%lld\n",l-1);
	cal(l-1);
	for(int i=1;i<=n;++i)ans[i]?printf("%d\n",ans[i]):printf("%d\n",d);
	return 0;
}
